package com.dhecp.project.storage.service.impl;

import com.alibaba.fastjson.JSON;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.utils.MessageUtils;
import com.dhecp.common.utils.RandomValueUtils;
import com.dhecp.common.utils.TypeUtils;
import com.dhecp.core.utils.PageUtils;
import com.dhecp.core.utils.ReflectUtils;
import com.dhecp.framework.util.ShiroUtils;
import com.dhecp.project.common.domain.ModuleNID;
import com.dhecp.project.common.domain.RecordCheck;
import com.dhecp.project.common.domain.UpdateFlow;
import com.dhecp.project.common.service.impl.BaseModuleServiceImpl;
import com.dhecp.project.finance.domain.AccountCountForCompany;
import com.dhecp.project.finance.domain.AccountDetailedForCompany;
import com.dhecp.project.finance.mapper.AccountCountForCompanyMapper;
import com.dhecp.project.finance.mapper.AccountDetailedForCompanyMapper;
import com.dhecp.project.storage.domain.HwFinalstatement;
import com.dhecp.project.storage.domain.HwFinalstatementSelect;
import com.dhecp.project.storage.domain.HwFinalstatementdetail;
import com.dhecp.project.storage.domain.HwTailprogram;
import com.dhecp.project.storage.enums.TailprogramEnum;
import com.dhecp.project.storage.mapper.*;
import com.dhecp.project.storage.service.HwFinalstatementService;
import liquibase.pro.packaged.A;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.dhecp.core.constant.DataFiltering;
import com.dhecp.project.system.service.SysDictionaryForFieldService;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.beans.Transient;
import java.util.*;

/**
 * 尾程对账单(HwFinalstatement表)服务实现类
 *
 * @author fxz
 * @since 2023-09-11 15:14:20
 */
@Service("hwFinalstatementService")
public class HwFinalstatementServiceImpl extends BaseModuleServiceImpl implements HwFinalstatementService {
    @Autowired
    private HwFinalstatementMapper hwFinalstatementMapper;
    
    @Autowired
    private SysDictionaryForFieldService dictionaryForFieldService;

    @Autowired
    private HwFinalstatementdetailMapper hwFinalstatementdetailMapper;

    @Autowired
    private HwTailprogramMapper hwTailprogramMapper;

    @Autowired
    private AccountCountForCompanyMapper accountCountForCompanyMapper;

    @Autowired
    private AccountDetailedForCompanyMapper businessMapper;

    @Autowired
    private HwFinalPaymentSonMapper hwFinalPaymentSonMapper;

    /**
     * 通过guid查询单条数据
     *
     * @param params 对象
     * @return 实例对象
     */
    @Override
    public HwFinalstatement queryFirstRecord(Map<String, Object> params) throws Exception{
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句
        return this.hwFinalstatementMapper.selectFirstRecordByNid(params);
    }



    /**
    * 查询列表数据
    */
    @Override
    public List<HwFinalstatement> queryList(Map<String, Object> params) throws Exception{
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句

        if (params.get("field") == null || params.get("field") == ""){
            String orderBy = "t1.bid DESC";
            PageUtils.startPageOrder(orderBy);
        }else{
            PageUtils.startPage();
        }

        return this.hwFinalstatementMapper.queryList(params);
    }

    @Override
    @Transactional(timeout = 120, propagation = Propagation.REQUIRES_NEW)
    public AjaxResult saveData(Map<String, Object> params) {
        params.put("businessEntity", new HwFinalstatement());
        AjaxResult ajaxResult = this.saveDataBase(params);
        Map<String, Object> infoMap = (Map<String, Object>) ajaxResult.get("infoMap");
        String resNid = infoMap.get("nid").toString();
        HwFinalstatement hwFinalstatement = JSON.parseObject(params.get("infoMap").toString(), HwFinalstatement.class);
        List<HwFinalstatementdetail> onSonData = new ArrayList<>();
        if (params.containsKey("sonData")){
            onSonData = JSON.parseArray(params.get("infoItems").toString(), HwFinalstatementdetail.class);
        }
        List<RecordCheck> guidMapList = hwFinalstatementMapper.findRecords(resNid);

        Map<String, Object> guidMap = new HashMap<String, Object>();
        if (!guidMapList.isEmpty()){
            if (infoMap.get("newNid") != null && "1".equals(infoMap.get("newNid").toString())){ //单号重复验证
                throw new RuntimeException(MessageUtils.message("module.error.retry"));
            }
            for (RecordCheck recordCheck : guidMapList){
                if (recordCheck != null && recordCheck.getGuid() != null){
                    guidMap.put(recordCheck.getGuid().toString(), "1");
                }
            }
        }

        if (onSonData == null || onSonData.size() == 0){
            resNid = "0";
        }else{
            resNid = infoMap.get("nid").toString();
            String guid = "";
            if (hwFinalstatement.getGuid() == null){
                guid = RandomValueUtils.getGUID();
                hwFinalstatement.setGuid(guid);
            }else{
                guid = hwFinalstatement.getGuid().toString();
            }
            for (String field : infoMap.keySet()) { //遍历非网格字段，并赋值到实体中
                Object fieldValue = infoMap.get(field);
                ReflectUtils.setValue(hwFinalstatement, field, fieldValue);
            }
            if (guidMap.get(guid) == null){
                hwFinalstatementMapper.insert(hwFinalstatement);
            }else{
                hwFinalstatementMapper.update(hwFinalstatement);
                guidMap.remove(guid);
            }
            List<HwFinalstatementdetail> lodData = hwFinalstatementdetailMapper.queryListTpcode(hwFinalstatement.getBid());

            if (lodData.size()>0){
                for (HwFinalstatementdetail item : lodData
                ) {
                    hwFinalstatementdetailMapper.delete(item);
                    //已审核
                    hwTailprogramMapper.updateState(item.getBid(), TailprogramEnum.StateName.SUCCESS.value);
                }
            }

            Map<String, Object> params1 = new HashMap<String, Object>();
            HwTailprogram hwTailprogram1;
            for (HwFinalstatementdetail item : onSonData
            ) {


                //查询尾程单数据
                params1.put("guid",item.getPguid());
                hwTailprogram1 = hwTailprogramMapper.selectFirstRecordByNid(params1);
                item.setGuid(RandomValueUtils.getGUID());
                item.setCodebox(hwTailprogram1.getCodebox());
                item.setCodeshipment(hwTailprogram1.getCodeshipment());
                item.setCodeplan(hwTailprogram1.getCodeplan());
                item.setTpcode(hwFinalstatement.getBid());
                item.setTailprogram(hwTailprogram1.getTailprogram());
                item.setChannelcode(hwTailprogram1.getChannelcode());
                item.setCodecompany(hwTailprogram1.getCodecompany());
                item.setVgsjc(hwTailprogram1.getVgsjc());
                item.setSellerid(hwTailprogram1.getSellerid());
                item.setShipmentid(hwTailprogram1.getShipmentid());
                item.setNumbox(hwTailprogram1.getNumbox());
                item.setLaunchwarehouse(hwTailprogram1.getLaunchwarehouse());
                item.setDestinationfulfillmentcenterid(hwTailprogram1.getDestinationfulfillmentcenterid());
                item.setCity(hwTailprogram1.getCity());
                item.setCountrycode(hwTailprogram1.getCountrycode());
                item.setWeightreal(hwTailprogram1.getWeightreal());
                item.setWeightvol(hwTailprogram1.getWeightvol());
                item.setWeightcal(hwTailprogram1.getWeightcal());
                item.setLastvoyagechargext(hwTailprogram1.getLastvoyagecharge());
                item.setNumcommodity(hwTailprogram1.getNumcommodity());
                item.setCodeqdcompany(hwTailprogram1.getCodeqdcompany());
                item.setNamecompany(hwTailprogram1.getNamecompany());
                item.setBid(hwTailprogram1.getBid());
                item.setPguid(hwTailprogram1.getPguid());
                item.setStockOutCode(hwTailprogram1.getStockOutCode());
                item.setStateName(TailprogramEnum.StateName.CHECKINGACCOUNTS.value);
                hwFinalstatementdetailMapper.insert(item);

                //尾程单对账中
                hwTailprogramMapper.updateState(item.getBid(), TailprogramEnum.StateName.CHECKINGACCOUNTS.value);
            }
        }

        if (!guidMap.isEmpty()){
            for (String guid : guidMap.keySet()){
                List<HwFinalstatementdetail> lodData = hwFinalstatementdetailMapper.queryListTpcode(hwFinalstatement.getBid());
                hwFinalstatementdetailMapper.deleteTpcode(hwFinalstatement.getBid());
                hwFinalstatementMapper.delete(guid);
                for (HwFinalstatementdetail hwFinalstatementdetail : lodData){
                    hwTailprogramMapper.updateState(hwFinalstatementdetail.getBid(), TailprogramEnum.StateName.SUCCESS.value);
                }
            }
        }

        return AjaxResult.success(MessageUtils.message("module.success.issuccess"),resNid);
    }


    /**
     *@Description: 查询前一单NID、BID
     *@Param: [params] nid 必要参数：当前 单据编码
     *@return: com.dhecp.common.core.domain.AjaxResult  (data.nid 前一单NID， data.bid 前一单BID)
     *@Author: hlf
     *@date: 2022-05-09 10:08
     */
    @Override
    public AjaxResult queryLastNid(Map<String, Object> params) throws Exception {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        if (params.get("nid") == null || params.get("nid") == ""){
            params.put("nid", "0");
        }
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句
        ModuleNID moduleNID = hwFinalstatementMapper.selectLastNid(params);
        if (moduleNID == null){
            dataMap.put("nid", "0");
            dataMap.put("bid", "0");
            return AjaxResult.warn(MessageUtils.message("module.warn.isfirstnid"), TypeUtils.mapToJson(dataMap).toString());
        }
        dataMap.put("nid", moduleNID.getNid().toString());
        dataMap.put("bid", moduleNID.getBid().toString());
        return AjaxResult.success(MessageUtils.message("module.success.issuccess"), TypeUtils.mapToJson(dataMap).toString());
    }


    /**
     *@Description: 查询后一单NID、BID
     *@Param: [params] nid 必要参数：当前 单据编码
     *@return: com.dhecp.common.core.domain.AjaxResult  (data.nid 后一单NID， data.bid 后一单BID)
     *@Author: hlf
     *@date: 2022-05-09 10:09
     */
    @Override
    public AjaxResult queryNextNid(Map<String, Object> params) throws Exception {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        if (params.get("nid") == null || params.get("nid") == "" || "0".equals(params.get("nid").toString())){
            dataMap.put("nid", "0");
            dataMap.put("bid", "0");
            return AjaxResult.warn(MessageUtils.message("module.warn.isfinallynid"), TypeUtils.mapToJson(dataMap).toString());
        }
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句
        ModuleNID moduleNID = hwFinalstatementMapper.selectNextNid(params);
        if (moduleNID == null){
            dataMap.put("nid", "0");
            dataMap.put("bid", "0");
            return AjaxResult.warn(MessageUtils.message("module.warn.isfinallynid"), TypeUtils.mapToJson(dataMap).toString());
        }
        dataMap.put("nid", moduleNID.getNid().toString());
        dataMap.put("bid", moduleNID.getBid().toString());
        return AjaxResult.success(MessageUtils.message("module.success.issuccess"), TypeUtils.mapToJson(dataMap).toString());
    }


    /**
     *@Description: 流转  —— 添加流程任务、修改流程状态及生效标志
     *@Param: [params] tableDataId 必要参数：单据编码（nid）
     *@return: com.dhecp.common.core.domain.AjaxResult
     *@Author: hlf
     *@date: 2022-05-09 10:11
     */
    @Override
    @Transactional(timeout=120,propagation= Propagation.REQUIRES_NEW)
    public AjaxResult updateFlowGo(Map<String, Object> params) {
        Map<String, Object> infoMap = new HashMap<String, Object>();
        String nid = "0";
        if (params.get("tableDataId") == null || params.get("tableDataId") ==""){
            return AjaxResult.error(MessageUtils.message("module.error.lack","单据编码【tableDataId】"));
        }else{
            nid = params.get("tableDataId").toString();
        }
        params.put("nid", nid);
        List<HwFinalstatement> businessDataList = hwFinalstatementMapper.selectByNid(params);
        if (businessDataList == null || businessDataList.size() == 0){
            return AjaxResult.error(MessageUtils.message("module.error.nodata"));
        }else{
            infoMap.put("cid", businessDataList.get(0).getCid());
            infoMap.put("bUser", businessDataList.get(0).getbUser());
            infoMap.put("bDept", businessDataList.get(0).getbDept());
            infoMap.put("procInstId", businessDataList.get(0).getProcInstId());
            infoMap.put("activeFlow", businessDataList.get(0).getActiveFlow());
            infoMap.put("createTime", businessDataList.get(0).getCreateTime());
            params.put("infoMap", TypeUtils.mapToJson(infoMap).toString());
            params.put("activeFlowOld", businessDataList.get(0).getActiveFlow());
        }

        //流程处理公共方法，返回单据（流转、回退等）后的流程状态信息
        if (params.get("optType") == null || params.get("optType") == ""){
            params.put("optType", "go");
        }

        UpdateFlow updateFlow = new UpdateFlow();
        updateFlow = this.FlowDealBase(params);

        List<AccountDetailedForCompany> accountList =new ArrayList<>();
        List<AccountCountForCompany> accountCountForCompanyList =new ArrayList<>();
        AccountCountForCompany ysAccount;
        for (HwFinalstatement businessData : businessDataList) {
            updateFlow.setGuid(businessData.getGuid().toString());
            hwFinalstatementMapper.updateFlow(updateFlow);

            if (updateFlow.getActiveFlow().equals("end")){
                // 逸思账户
                ysAccount = accountCountForCompanyMapper.queryFirstByVGsBm("GS0641");
                if (ysAccount == null){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return AjaxResult.error("逸思精品实时资金不存在,请核实后再操作!");
                }
                //查询详情信息
                List<HwFinalstatementdetail> hwFinalstatementdetailList = hwFinalstatementdetailMapper.queryListTpcode(businessData.getBid());
                for (HwFinalstatementdetail hwFinalstatementdetail : hwFinalstatementdetailList) {
                    hwFinalstatementdetailMapper.updateState(hwFinalstatementdetail.getGuid(), TailprogramEnum.StateName.HAVERECONCILED.value);

                    //已对账
                    hwTailprogramMapper.updateState(hwFinalstatementdetail.getBid(), TailprogramEnum.StateName.HAVERECONCILED.value);

                    //                     物流公司渠道
                    AccountCountForCompany logisticsQdAccount = accountCountForCompanyMapper.queryFirstByVGsBm(hwFinalstatementdetail.getCodeqdcompany());
                    if (logisticsQdAccount == null) {
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        return AjaxResult.error("物流渠道实时资金不存在,请核实后再操作!");
                    }
                    //资金流水(从逸思精品支出到物流部对应的渠道账户)
                    AccountDetailedForCompany account = new AccountDetailedForCompany();
                    account.setGuid(RandomValueUtils.getGUID());
                    account.setvGsBm(ysAccount.getvGsBm());
                    account.setvGsMc(ysAccount.getvGsMc());
                    account.setvGsJc(ysAccount.getvGsJc());
                    account.setvGsBmP(logisticsQdAccount.getvGsBm());
                    account.setvGsMcP(logisticsQdAccount.getvGsMc());
                    account.setvGsJcP(logisticsQdAccount.getvGsJc());
                    account.setvJyLx("物流服务→头程运费");
                    account.setfJe(-Double.valueOf(hwFinalstatementdetail.getLastvoyagechargefk().toString()));
                    account.setdJySj(businessData.getCreateTime());
                    account.setdShSj(new Date());
                    account.setvBz("尾程对账单号:" + businessData.getBid() + "，FBA编号:" + hwFinalstatementdetail.getShipmentid() + "，海外尾程单:" + hwFinalstatementdetail.getBid()+ "，海外尾程出库单号:" + hwFinalstatementdetail.getStockOutCode());
                    account.setCreateTime(new Date());
                    accountList.add(account);

                    AccountDetailedForCompany account1 = new AccountDetailedForCompany();
                    account1.setGuid(RandomValueUtils.getGUID());
                    account1.setvGsBm(logisticsQdAccount.getvGsBm());
                    account1.setvGsMc(logisticsQdAccount.getvGsMc());
                    account1.setvGsJc(logisticsQdAccount.getvGsJc());
                    account1.setvGsBmP(ysAccount.getvGsBm());
                    account1.setvGsMcP(ysAccount.getvGsMc());
                    account1.setvGsJcP(ysAccount.getvGsJc());
                    account1.setvJyLx("物流服务→头程运费");
                    account1.setfJe(Double.valueOf(hwFinalstatementdetail.getLastvoyagechargefk().toString()));
                    account1.setdJySj(businessData.getCreateTime());
                    account1.setdShSj(new Date());
                    account1.setvBz("尾程对账单号:" + businessData.getBid() + "，FBA编号:" + hwFinalstatementdetail.getShipmentid() + "，海外尾程单:" + hwFinalstatementdetail.getBid()+ "，海外尾程出库单号:" + hwFinalstatementdetail.getStockOutCode());
                    account1.setCreateTime(new Date());
                    accountList.add(account1);
                }
            }
        }

        //创建临时表 -  新增流水 - 删除临时表 （必须同时新增临时表才能跳过资金的判断）
        businessMapper.insertBatchNew(accountList);

        return AjaxResult.success(MessageUtils.message("module.success.issuccess"), nid);
    }

    /**
     *@Description: 退回  —— 添加流程任务、修改流程状态及生效标志
     *@Param: [params] tableDataId 必要参数：单据编码（nid）
     *@return: com.dhecp.common.core.domain.AjaxResult
     *@Author: hlf
     *@date: 2022-05-09 10:11
     */
    @Override
    @Transactional(timeout=120,propagation= Propagation.REQUIRES_NEW)
    public AjaxResult updateFlowBack(Map<String, Object> params) {
        Map<String, Object> infoMap = new HashMap<String, Object>();
        String nid = "0";
        if (params.get("tableDataId") == null || params.get("tableDataId") ==""){
            return AjaxResult.error(MessageUtils.message("module.error.lack","单据编码【tableDataId】"));
        }else{
            nid = params.get("tableDataId").toString();
        }
        params.put("nid", nid);
        List<HwFinalstatement> businessDataList = hwFinalstatementMapper.selectByNid(params);
        if (businessDataList == null || businessDataList.size() == 0){
            return AjaxResult.error(MessageUtils.message("module.error.nodata"));
        }else{
            //判断是否被付款单使用 不允许回退
            int count = hwFinalPaymentSonMapper.countFsBid(businessDataList.get(0).getBid());
            if (count != 0){
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("该对账单已被付款,不允许退回!");
            }
            infoMap.put("cid", businessDataList.get(0).getCid());
            infoMap.put("bUser", businessDataList.get(0).getbUser());
            infoMap.put("bDept", businessDataList.get(0).getbDept());
            infoMap.put("procInstId", businessDataList.get(0).getProcInstId());
            infoMap.put("activeFlow", businessDataList.get(0).getActiveFlow());
            infoMap.put("createTime", businessDataList.get(0).getCreateTime());
            params.put("infoMap", TypeUtils.mapToJson(infoMap).toString());
            params.put("activeFlowOld", businessDataList.get(0).getActiveFlow());
        }

        //流程处理公共方法，返回单据（流转、回退等）后的流程状态信息
        if (params.get("optType") == null || params.get("optType") == ""){
            params.put("optType", "back");
        }
        UpdateFlow updateFlow = new UpdateFlow();
        updateFlow = this.FlowDealBase(params);

        List<AccountDetailedForCompany> accountList =new ArrayList<>();
        List<AccountCountForCompany> accountCountForCompanyList =new ArrayList<>();
        AccountCountForCompany ysAccount;
        for (HwFinalstatement businessData : businessDataList) {
            updateFlow.setGuid(businessData.getGuid().toString());
            hwFinalstatementMapper.updateFlow(updateFlow);

            if (infoMap.get("activeFlow").equals("end")){
                // 逸思账户
                ysAccount = accountCountForCompanyMapper.queryFirstByVGsBm("GS0641");
                if (ysAccount == null){
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return AjaxResult.error("逸思精品实时资金不存在,请核实后再操作!");
                }
                //查询详情信息
                List<HwFinalstatementdetail> hwFinalstatementdetailList = hwFinalstatementdetailMapper.queryListTpcode(businessData.getBid());
                for (HwFinalstatementdetail hwFinalstatementdetail : hwFinalstatementdetailList) {
                    hwFinalstatementdetailMapper.updateState(hwFinalstatementdetail.getGuid(), TailprogramEnum.StateName.CHECKINGACCOUNTS.value);
                    //已对账
                    hwTailprogramMapper.updateState(hwFinalstatementdetail.getBid(), TailprogramEnum.StateName.CHECKINGACCOUNTS.value);

                    //                     物流公司渠道
                    AccountCountForCompany logisticsQdAccount = accountCountForCompanyMapper.queryFirstByVGsBm(hwFinalstatementdetail.getCodeqdcompany());
                    if (logisticsQdAccount == null) {
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        return AjaxResult.error("物流渠道实时资金不存在,请核实后再操作!");
                    }
                    //资金流水(从逸思精品支出到物流部对应的渠道账户)
                    AccountDetailedForCompany account = new AccountDetailedForCompany();
                    account.setGuid(RandomValueUtils.getGUID());
                    account.setvGsBm(ysAccount.getvGsBm());
                    account.setvGsMc(ysAccount.getvGsMc());
                    account.setvGsJc(ysAccount.getvGsJc());
                    account.setvGsBmP(logisticsQdAccount.getvGsBm());
                    account.setvGsMcP(logisticsQdAccount.getvGsMc());
                    account.setvGsJcP(logisticsQdAccount.getvGsJc());
                    account.setvJyLx("物流服务→头程运费");
                    account.setfJe(Double.valueOf(hwFinalstatementdetail.getLastvoyagechargefk().toString()));
                    account.setdJySj(businessData.getCreateTime());
                    account.setdShSj(new Date());
                    account.setvBz("(退回)尾程对账单号:" + businessData.getBid() + "，FBA编号:" + hwFinalstatementdetail.getShipmentid() + "，海外尾程单:" + hwFinalstatementdetail.getBid()+ "，海外尾程出库单号:" + hwFinalstatementdetail.getStockOutCode());
                    account.setCreateTime(new Date());
                    accountList.add(account);

                    AccountDetailedForCompany account1 = new AccountDetailedForCompany();
                    account1.setGuid(RandomValueUtils.getGUID());
                    account1.setvGsBm(logisticsQdAccount.getvGsBm());
                    account1.setvGsMc(logisticsQdAccount.getvGsMc());
                    account1.setvGsJc(logisticsQdAccount.getvGsJc());
                    account1.setvGsBmP(ysAccount.getvGsBm());
                    account1.setvGsMcP(ysAccount.getvGsMc());
                    account1.setvGsJcP(ysAccount.getvGsJc());
                    account1.setvJyLx("物流服务→头程运费");
                    account1.setfJe(-Double.valueOf(hwFinalstatementdetail.getLastvoyagechargefk().toString()));
                    account1.setdJySj(businessData.getCreateTime());
                    account1.setdShSj(new Date());
                    account1.setvBz("(退回)尾程对账单号:" + businessData.getBid() + "，FBA编号:" + hwFinalstatementdetail.getShipmentid() + "，海外尾程单:" + hwFinalstatementdetail.getBid()+ "，海外尾程出库单号:" + hwFinalstatementdetail.getStockOutCode());
                    account1.setCreateTime(new Date());
                    accountList.add(account1);
                }
            }
        }

        //创建临时表 -  新增流水 - 删除临时表 （必须同时新增临时表才能跳过资金的判断）
        businessMapper.insertBatchNew(accountList);

        return AjaxResult.success(MessageUtils.message("module.success.issuccess"), nid);
    }


    /**
     * 物流对账调用数据
     * @param params
     * @return
     * @throws Exception
     */
    @Override
    public List<HwFinalstatementSelect> queryListSelect(Map<String, Object> params) throws Exception {
        params.put(DataFiltering.TABLE_ALIAS, "t1");	//查询表别名
        params.put(DataFiltering.DATA_WHERE, dictionaryForFieldService.getWhereStr(params));	//常规查询条件SQL语句
        params.put(DataFiltering.DATA_SCODE, dictionaryForFieldService.getDataScode(params));	//数据权限查询条件SQL语句

        PageUtils.startPage();

        return hwFinalstatementMapper.queryListSelect(params);
    }
}

